<?php
/**
 * a util base hash extension
 * md5('data'); equals hash('md5', 'data'); equals $ctx = hash_init('md5'); hash_update($ctx, 'data'); hash_final($ctx);
 * 
 * @author tom.wang<tom.wang.sz@qq.com>
 */
class HashUtil {
	/**
	 * get support algo list used in hash extension
	 * 
	 * @return array
	 */
	public static function algosList() {
		return hash_algos();
	}
	
	/**
	 * hmac means "keyed-Hash Message Authentication Code"
	 * compare to md5, the key in this method improve the security
	 *
	 * @return string
	 */
	public static function hmac($algo, $data, $key, $raw_output = false) {
		return hash_hmac($algo, $data, $key, $raw_output);
	}
	
	/**
	 * three method to realize md5 algo
	 */
	public static function md5($data, $raw_output = false) {
		// method 1
		// return md5($data, $raw_output);
		
		// method 2
		// return hash('md5', $data, $raw_output);
		
		// method 3
		// $ctx = hash_init('md5');
		// hash_update($ctx, 'data');
		// return hash_final($ctx, $raw_output);
	}
}
?>